const App = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 选项卡标示
    dataType: 'not_use',

    // 列表高度
    swiperHeight: 0,

    // 列表
    list: [],
    selectShow: false,//控制下拉列表的显示隐藏，false隐藏、true显示
    selectData: ['全部','未审核','已通过','已拒绝','草稿'],//下拉列表的数据
    index: 0,//选择的下拉列表下标
    // show
    notcont: false,
    status: 0,
    hasFubiaoPromission: false
  },
 // 点击下拉显示框
 selectTap() {
  this.setData({
    selectShow: !this.data.selectShow
  });
},
// 点击下拉列表
optionTap(e) {
  let Index = e.currentTarget.dataset.index;//获取点击的下拉列表的下标
  this.setData({
    index: Index,
    selectShow: !this.data.selectShow
  });
  this.GetUserBaoMingList()
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 设置swiper的高度
    this.setSwiperHeight();
    let hasFubiaoPromission = wx.getStorageSync('hasFubiaoPromission')
    let hasZhuBiaoPromission = wx.getStorageSync('hasZhuBiaoPromission')
    this.setData({
      hasFubiaoPromission: hasFubiaoPromission
    })
    if (hasFubiaoPromission||hasZhuBiaoPromission) {
      this.data.status = 4
      this.setData({
        dataType:'chengzhongcunfujian'
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 获取优惠券列表
    this.GetUserBaoMingList();
  },

  /**
   * 获取列表
   */
  GetUserBaoMingList: function () {
    let _this = this
    var status;
    var url = '';
    switch (_this.data.status) {
      case 0:
        status = 0;
        url = "GetXiaoQuXunChaHis"
        break;
      case 1:
        status = 1;
        url = 'GetShuiChangXunChaHis'
        break;
      case 2:
        status = 2;
        url = 'GetShuiKuChaHis'
        break;
      case 3:
        status = 3;
        url = 'GetChengZhongCunXunChaHis'
        break;
      case 4:
        status = 4;
        url = 'GetChengZhongCunFuBiaoHis'
        break;
    }
    _this.setData({
      status: status
    })
    if (status == 4) {
      let selectVal  = null;
      switch (this.data.index){
        case 1:
          selectVal = 0;
          break;
        case 2:
          selectVal = 1;
          break;
        case 3:
          selectVal = 2;
          break;
        case 4:
          selectVal = 99;
          break;
      }
      wx.request({
        url: App.api_test + 'GetChengZhongCunFuBiaoHis',
        header: {
          'content-type': 'application/JSON',
        },
        method: 'POST',
        data: {
          openId: wx.getStorageSync('openid'),
          userId: wx.getStorageSync('user_id'),
          status: selectVal
        },
        success(res) {
          console.log('城中村附件历史', res)
          _this.setData({
            list: res.data,
            notcont: false
          });
        },
        fail(res) {
          console.log('城中村附件历史异常', res);
        }
      })
    } else {
      App._post_form(url, {
        status: status
      }, (res) => {
        _this.setData({
          list: res,
          notcont: false
        });
      })
    }
  },
  /**
   * 设置swiper的高度
   */
  setSwiperHeight: function () {
    // 获取系统信息(拿到屏幕宽度)
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = Math.floor(rpx * 80) + 1, // tap高度
      swiperHeight = systemInfo.windowHeight; // swiper高度
      // swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      swiperHeight
    });
  },

  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    let _this = this;
    var url = ''
    _this.setData({
      list: {},
      dataType: e.target.dataset.current
    }, function () {
      // 获取优惠券列表
      let status = 0;
      switch (e.target.dataset.current) {
        case 'not_use':
          status = 0;
          url = "GetXiaoQuXunChaHis"
          break;
        case 'is_use':
          status = 1;
          url = 'GetShuiChangXunChaHis'
          break;
        case 'is_expire':
          status = 2;
          url = 'GetShuiKuChaHis'
          break;
        case 'chengzhongcun':
          status = 3;
          url = 'GetChengZhongCunXunChaHis'
          break;
        case 'chengzhongcunfujian':
          status = 4;
          url = 'GetChengZhongCunFuBiaoHis'
          break;
      }
      _this.setData({
        status: status
      })
      if (status == 4) {
        wx.request({
          url: App.api_test + 'GetChengZhongCunFuBiaoHis',
          header: {
            'content-type': 'application/JSON',
          },
          method: 'POST',
          data: {
            openId: wx.getStorageSync('openid'),
            userId: wx.getStorageSync('user_id')
          },
          success(res) {
            console.log('城中村附件历史', res)
            _this.setData({
              list: res.data,
              notcont: false
            });
          },
          fail(res) {
            console.log('城中村附件历史异常', res);
          }
        })
      } else {
        App._post_form(url, {
          status: status
        }, (res) => {
          console.log(res)
          _this.setData({
            list: res,
            notcont: false
          });
        })
      }
    });
  },
  delete(e) {
    let _this = this;

    wx.showModal({
      content: '确定要删除吗？',
      title: '删除',
      success: (ee) => {
        if (ee.confirm) {
          var url = ''
          var status = 0
          switch (_this.data.status) {
            case 0:
              status = 0;
              url = "DeleXiaoQuXunCha"
              break;
            case 1:
              status = 1;
              url = 'DelShuiChang'
              break;
            case 2:
              status = 2;
              url = 'DeleShuiKu'
              break;
            case 3:
              status = 3;
              url = 'DeleChengZhongCun'
              break;
            case 4:
              status = 4;
              url = 'DelChengZhongCunFuBiao'
              break;
          }
          if (status == 4) {
            wx.request({
              url: App.api_test + 'DelChengZhongCunFuBiao',
              header: {
                'content-type': 'application/JSON',
              },
              method: 'POST',
              data: {
                id: e.currentTarget.dataset.id
              },
              success(res) {
                console.log('城中村附件删除', res)
                wx.showToast({
                  title: res.data,
                })
                _this.GetUserBaoMingList()
              },
              fail(res) {
                console.log('城中村附件删除异常', res);
              }
            })
          } else {
            App._post_form(url, { id: e.currentTarget.dataset.id }, (res) => {
              wx.showToast({
                title: res,
              })
              _this.GetUserBaoMingList()
            })
          }
        }
      }
    })
  },
  go(e) {
    var url = '';
    let status = 0;
    switch (this.data.dataType) {
      case 'not_use':
        status = 0;
        url = "/pages/xiaoquEditor/index"
        break;
      case 'is_use':
        status = 1;
        url = '/pages/shuichangEditor/index'
        break;
      case 'is_expire':
        status = 2;
        url = '/pages/shuikuEditor/index'
        break;
      case 'chengzhongcun':
        status = 3;
        url = '/pages/chengzhongcunEditor/index'
        break;
      case 'chengzhongcunfujian':
        status = 4;
        url = '/pages/dongbiao_c_edit/index'
        break;
    }
    console.log('城中村',e.currentTarget.dataset.cun)
    let ChengZhongCunId = e.currentTarget.dataset.cun
    if(ChengZhongCunId){
      App.globalData.ChengZhongCunId = ChengZhongCunId
    }
    console.log(url)
    wx.navigateTo({
      url: `${url}?id=${e.currentTarget.dataset.id}`,
    })
  }

});